package com.elinkway.infinitemovies.push;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.BigTextStyle;

import com.elinkway.infinitemovies.bean.PushData;
import com.elinkway.infinitemovies.bigdata.BigDataConstants;
import com.elinkway.infinitemovies.bigdata.BigDataPushRecvTask;
import com.elinkway.infinitemovies.bigdata.BigDataStats;
import com.le123.ysdq.R;

/**
 * 推送通知
 * @author liuliwei
 *
 */
public class PushNotificationSender {

	/**
	 * push notification 的id
	 */
	private static final int PUSH_NOTIFICATION_ID = 12334;
	/**
	 * 创建并发送Notification
	 * @param context
	 * @param pushData
	 */
	public static void sendNotify(Context context, PushData pushData){
		NotificationCompat.BigTextStyle textStyle = new BigTextStyle();
        textStyle
                .setBigContentTitle(pushData.getTitle())
//              .setSummaryText("SummaryText")
                .bigText(pushData.getMsg());

		NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
		Notification notification = builder.setAutoCancel(true)
			.setContentText(pushData.getMsg())
			.setContentTitle(pushData.getTitle())
			.setSmallIcon(R.drawable.ic_status)
			.setContentIntent(PushIntentFactory.getPendingIntentByType(context,pushData))
			.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher))
			.setWhen(System.currentTimeMillis())
			.setTicker(pushData.getMsg())
			.setDefaults(Notification.DEFAULT_SOUND)
			.setStyle(textStyle)
			.build();
		
//		.addAction(R.drawable.refresh, "ceshi", null)
//		.addAction(R.drawable.actionbar_ic_about, "ceshi2", null)
		 NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
		 manager.notify("push", PUSH_NOTIFICATION_ID, notification);
		 // 友盟上报相关
		 // 上报收到推送事件
		PushStatsPoster.postPushStats(pushData.getType());
		BigDataPushRecvTask bdstats = new BigDataPushRecvTask();
		String type = pushData.getType();
		if(type.equalsIgnoreCase(PushData.TYPE.ALBUM)){
			bdstats.setApType(BigDataConstants.AP_VAL_PUSH_TYPE_ALBUM);
		}
		else if(type.equalsIgnoreCase(PushData.TYPE.TOPIC)){
			bdstats.setApType(BigDataConstants.AP_VAL_PUSH_TYPE_THEME);
		}
		else if(type.equalsIgnoreCase(PushData.TYPE.HTML)){
			bdstats.setApType(BigDataConstants.AP_VAL_PUSH_TYPE_PAGE);
		} else if(type.equalsIgnoreCase(PushData.TYPE.ACTIVITY)){
			bdstats.setApType(BigDataConstants.AP_VAL_PUSH_TYPE_ACTIVITY);
		}else{
			bdstats.setApType("");
		}
		bdstats.setApName(pushData.getTitle());
		bdstats.setAR(BigDataConstants.AR_SUCCESS);
		BigDataStats.post(bdstats);
	}
}
